const Router = require('koa-router');
const crypto = require('crypto');

const query = require('../lib/mysql');
const wrapper = require('../util/wrapper');
const checkError = require('../util/checkError');

const router = new Router();

router.prefix('/api/system');

module.exports = router;

/**
 * 获取广告文案  advertise
 * 获取用户协议  protocol
 */
router.get('/:title', async (ctx, next) => {
  const { title } = ctx.params;
  let list = await query(`
  select content from system where title="${title}"
  `);

  if (checkError(list) || !Array.isArray(list)) {
    ctx.body = await wrapper(new Error('服务异常.'));
    return false;
  }

  ctx.body = await wrapper(list);
});
